// 用mockjs模拟数据
import Mock from 'mockjs'
export const list = Mock.mock({
  'list|50': [
     {
      'id|+1': 1,
      'check|1': [true, false],
      'name': '@cname',
      'sex': '@pick(["男", "女"])',
      'age': '@integer(18, 60)',
      'address': '@county(true)',
      'img':'@image(200x200)',
      'card': /500\d{7}/,
      'self': /\d{17}[\dX]/,
      'tel': /1[3456789]\d{9}/,
      'clasz': '@pick(["内科-肺内科", "外科-普外科", "骨科", "神经内科", "消化内科", "心内科", "儿科", "妇产科", "眼科", "皮肤科"])',
      'type': '@pick(["专家号", "普通号", "特需号"])',
      'money|1': ['10.00', '15.00', '20.00', '30.00', '50.00', '60.00', '80.00', '100.00'],
      'status|0-3': 0,
      'day': '@date("yyyy-MM-dd")',
      'time': '@time("HH:mm")',
      'yvTime': '@datetime("yyyy-MM-dd HH:mm:ss")',
        "shengao": "@natural(150, 190)",
        "tizhong": "@natural(40, 100)",
        "BMI": function () {
            const weight = parseInt(this.tizhong);
            const height = parseInt(this.shengao);
            return (weight / ((height / 100) ** 2)).toFixed(1);
        },
        "xyssy": "@natural(90, 140)mm/Hg",
        "xyszy": "@natural(60, 90)mm/Hg",
        "xhdb": "@natural(80, 200)g/L",
        "hxb": "@natural(80, 200)g/L",
        "xxb": "@natural(80, 200)g/L",
        "dhxbjdz": "@natural(80, 200)g/L",
        "lbxbjdz": "@natural(80, 200)g/L",
        "ckfw": "115-150g/L"
    }
  ],
})
console.log('list', list)
Mock.mock(/\/api\/list/, 'get', function (options: any) {
  // 解析查询参数
  const params = new URLSearchParams(options.url.split('?')[1])
  const pageNum = parseInt(params.get('pageNum') as any) || 1
  const pageSize = parseInt(params.get('pageSize') as any) || 5

  // 计算分页数据
  const start = (pageNum - 1) * pageSize
  const end = start + pageSize
  const pageData = list.list.slice(start, end)
  return {
    code: 200,
    message: '获取数据成功',
    data: {
      total: list.list.length,
      list: pageData,
      pageNum,
      pageSize,
    },
  }
})

// 安排医生的数据机接口
// 定义科室列表
const departments = [
  '内科-心脏内科',
  '内科-呼吸内科',
  '内科-消化内科',
  '外科-普外科',
  '外科-骨科',
  '外科-神经外科',
  '妇产科-妇科',
  '妇产科-产科',
  '儿科',
  '眼科',
  '口腔科',
  '皮肤科',
  '精神科',
  '急诊科',
  '康复科'
]

// 定义日期数组
const weekDates = ['2021/01/01', '2021/01/02', '2021/01/03', '2021/01/04', '2021/01/05', '2021/01/06', '2021/01/07']
function numberToLetter(num:any) {
  return String.fromCharCode(65 + num); // 65 是 ASCII 码中 'A' 的值
}
// 生成日期数据模板
const dateDataTemplate = {}
weekDates.forEach(date => {
  const dateKey = date.replace(/\//g, '').split('').map(digit => 
    numberToLetter(parseInt(digit))
  ).join('');
  dateDataTemplate[`${dateKey}am|1`] = ['@natural(5, 20)/20', '休']
  dateDataTemplate[`${dateKey}pm|1`] = ['@natural(5, 20)/20', '休']
})

// 完整数据模板
export const dataTemplate = Mock.mock({
  'data|50': [
    {
      doctorId: '@id', // 生成唯一ID
      doctorName: '@cname', // 随机中文姓名
      department: () => Mock.Random.pick(departments), // 随机选择科室
      ...dateDataTemplate // 展开日期数据
    }
  ]
})
console.log("安排医生",dataTemplate)
Mock.mock(/\/api\/doctorList/, 'get', function (options: any) {
  // 解析查询参数
  const params = new URLSearchParams(options.url.split('?')[1])
  const pageNum = parseInt(params.get('pageNum') as any) || 1
  const pageSize = parseInt(params.get('pageSize') as any) || 5

  // 计算分页数据
  const start = (pageNum - 1) * pageSize
  const end = start + pageSize
  const pageData = dataTemplate.data.slice(start, end)
  return {
    code: 200,
    message: '获取数据成功',
    data: {
      total: dataTemplate.data.length,
      list: pageData,
      pageNum,
      pageSize,
    },
  }
})